// ==UserScript==
// @name         抖音/头条显示ID
// @namespace    http://tampermonkey.net/
// @version      0.2.5
// @description  try to take over the world!
// @author       suiyue
// @match        https://www.douyin.com/user/*
// @match        https://so.toutiao.com/search*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=douyin.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';
    const HOST = location.host;
    console.log(HOST);

    if (HOST == 'www.douyin.com') {
        debugger;
        let body = document.documentElement;
        // let myJson = JSON.parse(unescape(myscript.innerHTML));
        // let myUserID = myJson["63"]["user"]["user"]["uid"];
        let html = body.innerHTML;
        // "user\":{\"uid\":\"2669257430675517\",\"
        let myUserID = html.match(/"user\\":{\\"uid\\":\\"(.*?)\\"/);
        console.log(myUserID);
        let userInfo = document.querySelector("h1");
        let uuidHTML = document.createElement("span");
        // uuidHTML.style = "color: brown";
        uuidHTML.innerHTML = "<span style='color: brown;'>userID:" + myUserID[1] + "</span>";
        userInfo.append(uuidHTML);
        console.log(myUserID);
        alert("抖音ID："+myUserID[1])
    }

    if (HOST == 'so.toutiao.com') {
        let myDivs = document.querySelectorAll("div[class='cs-view cs-view-block cs-card-content']");
        let userDiv = document.querySelectorAll("div[class='flex-1 text-darker text-xl text-medium']");
        let i;
        for (i = 0; i < myDivs.length; i++) {
            let mya = myDivs[i].querySelector("a");
            let myHrefs = unescape(mya.getAttribute("href")).split("/");
            let uid = myHrefs[7];
            console.log(uid);
            let mySpan = userDiv[i].querySelector("span");
            let mydiv = document.createElement("div");
            mydiv.style = "color: brown";
            mydiv.innerHTML = "<span>userID:" + uid + "</span>";
            mySpan.append(mydiv);
        }
    }
})();